package com.think.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
/*@PropertySource(value = "classpath:jdbc.properties")*/
public class DataSourceConfig {

    //sqlite not support:destroyMethod = "close", name = "dataSource", initMethod = "init"
    @Bean(destroyMethod = "", name = "dataSource", initMethod = "")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
        /*DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName("org.sqlite.JDBC");
        dataSourceBuilder.url("jdbc:sqlite::resource:data/think.db");
        dataSourceBuilder.type(SQLiteDataSource.class);
        DataSource db = dataSourceBuilder.build();*/
        //return DataSourceBuilder.create().build();
        return new DruidDataSource();
    }

    /**
     * 注册一个StatViewServlet
     * 第二种方式，使用servlet3.0注解WebServlet，详见类：DruidStatViewServlet、
     * 第三种方式，使用配置文件
     *
     * @return

     @Bean public ServletRegistrationBean druidStatViewServlet() {
     ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
     servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
     //IP黑名单 (存在共同时，deny优先于allow)
     servletRegistrationBean.addInitParameter("deny", "192.168.1.73");
     servletRegistrationBean.addInitParameter("loginUsername", "admin");
     servletRegistrationBean.addInitParameter("loginPassword", "123456");
     servletRegistrationBean.addInitParameter("resetEnable", "false");
     return servletRegistrationBean;
     }*/

    /**
     * 注册一个：filterRegistrationBean
     *
     * @return

     @Bean public FilterRegistrationBean druidStatFilter() {
     FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
     filterRegistrationBean.addUrlPatterns("/*");
     filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
     return filterRegistrationBean;
     }*/
}
